﻿using System;
using Microsoft.SharePoint.Administration;
using System.Reflection;
namespace SharePoint.Orm.Helpers {
	public class SPWebConfigModificationHelper {
		public static SPWebConfigModification CreateSafeControlMod(string owner, Type type) {
			string assemblyName = type.Assembly.FullName;
			string classNamespace = type.Namespace;
			SPWebConfigModification mod = new SPWebConfigModification {
				Name = "SafeControl[@Assembly='" + assemblyName + "'][@Namespace='" + classNamespace + "']",
				Path = "configuration/SharePoint/SafeControls",
				Value = "<SafeControl Assembly=\"" + assemblyName + "\" Namespace=\"" + classNamespace + "\" TypeName=\"*\" Safe=\"True\" />",
				Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode,
				Owner = owner,
				Sequence = 0
			};
			return mod;
		}

		public static SPWebConfigModification CreateAssemblyMod(string owner, Assembly assembly) {
			string assemblyName = assembly.FullName;
			SPWebConfigModification mod = new SPWebConfigModification {
				Name = "add[@assembly='" + assemblyName + "']",
				Path = "configuration/system.web/compilation/assemblies",
				Value = "<add assembly=\"" + assemblyName + "\"/>",
				Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode,
				Owner = owner,
				Sequence = 0
			};
			return mod;
		}
	}
}
